#[allow(dead_code)]
enum Command {
    Undo,
    Redo,
    AddText(String),
    MoveCursor(i32, i32),
    Replace { from: String, to: String },
}

impl Command {
    fn serialize(&self) -> String {
        match self {
            Command::Undo => String::from("{\"cmd\":\"Undo\"}"),
            Command::Redo => String::from("{\"cmd\":\"Redo\"}"),
            Command::AddText(s) => {
                format!(
                    "{{\
                    \"cmd\":\"AddText\",\
                    \"text\":\"{s}\"
                    }}"
                )
            }
            Command::MoveCursor(x, y) => {
                format!(
                    "{{\
                    \"cmd\":\"MoveCursor\",\
                    \"x\":{x}\",\
                    \"y\":{y}\"
                    }}"
                )
            }
            Command::Replace { from, to } => {
                format!(
                    "{{\
                    \"cmd\":\"Replace\", \
                    \"from\":\"{from}\", \
                    \"to\":\"{to}\"
                    }}"
                )
            }
        }
    }
}

fn main() {
    let cmd1 = Command::Undo;
    let cmd2 = Command::AddText(String::from("hello"));
    let cmd3 = Command::Replace {
        from: String::from("hello"),
        to: String::from("world"),
    };
    let cmd4 = Command::MoveCursor(10, 20);
    // let cmd5 = Command::Redo;

    println!("{}", cmd1.serialize());
    println!("{}", cmd2.serialize());
    println!("{}", cmd3.serialize());
    println!("{}", cmd4.serialize());
    // println!("{}", cmd5.serialize());
}
